/**
 * mongoclient: 封装mongodb处理
 * bushaofeng 2012.1.7
 */

#ifndef __MONGOCLIENT_H_
#define __MONGOCLIENT_H_

#include <vector>
#include "mongo/client/dbclient.h"

using namespace std;
using namespace mongo;

class MongoClient:public DBClientConnection{
    public:
        MongoClient(){}
        MongoClient(const char* ip){
            connect(ip);
        }
        ~MongoClient(){}

        bool connect(const char* ip){
            try{
                DBClientConnection::connect(ip);
            }catch(DBException& e){
                return false;
            }
            fprintf(stdout, "Connect MongoDB OK.\n");
            return true;
        }

        /**
         * 查询函数
         * getid:是否返回键_id
         */

        BSONObj query(const char* collection, BSONObj obj, bool getid=false);
        vector<BSONObj> query_v(const char* collection, BSONObj obj, bool getid=false);
        BSONObj query_one(const char* collection, BSONObj obj, bool getid=false);


        /*
        void insert(const char* collection, BSONObj obj){return dc.insert(collection, obj);}
        void update(const char* collection, BSONObj key, BSONObj obj){return dc.update(collection, key, obj);}
        void remove(const char* collection, BSONObj key){return dc.remove(collection, key);}
        unsigned long long count(const char* collection, BSONObj key){return dc.count(collection, key);}
        */

        //DBClientConnection& getDBClient(){return dc;}

        enum{MONGO_CONTINUE, MONGO_END};
    private:
        //DBClientConnection      dc;
};

#endif
